<?php 
	require('../db_connect.php');
	
	$function = $_POST['function'];

	switch ($function){
	case "deleteRealm":
		deleteRealm($_POST['realm_id']);
		break;
	case "add":
		addRealm(		
		$_POST['realm_type'],
		$_POST['realm_color'],
		$_POST['realm_loc'],	
		$_POST['realm_level'],
		$_POST['realm_name'],
		$_POST['network_id'],
		$_POST['parent_realm']);
		break;
	}
		
function addRealm($realm_type,$realm_color,$realm_loc,$realm_level,$realm_name,$network_id,$parent_realm){
	$sql = "INSERT into realms values (DEFAULT, '$realm_type','$realm_color','$realm_loc','$realm_name','$network_id','$parent_realm','$realm_level')";
	$result = $db->Execute($sql);
}

function deleteRealm($realm_id){
	$sql = "DELETE FROM realms WHERE realm_id = " . $realm_id . ";";
	$result = $db->Execute($sql);	
	if(!$result)
	$result = "query failed";
	else
	$result = "Great Success!";
	echo '{"result":' . '"' . $result . '"' . '}';
}
?>

/*
<html>
<header>
<title>realmTableUpdater</title>
</header>
<body>
<?php 
if($result)
echo "the realm " . $realm_name . " has been added to the realms table.";
else
echo "shit hit the fan!";
?>		
</body>
</html>
